<?php

namespace pay\modules\frontend\models;

use Yii;

/**
 * This is the model class for table "pay_account_checking".
 *
 * @property int $id
 * @property int $app_id 实例id
 * @property string $app_name 实例名称
 * @property string $channel_id 支付渠道id
 * @property string $status 1-生成 ，2-未生成
 * @property string $down_url 下载地址
 * @property string $account_time 对账日期
 * @property string $create_time 创建时间
 */
class AccountChecking extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'pay_account_checking';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['app_id', 'channel_id', 'down_url', 'account_time', 'create_time'], 'required'],
            [['app_id'], 'integer'],
            [['status'], 'string'],
            [['account_time', 'create_time'], 'safe'],
            [['app_name'], 'string', 'max' => 64],
            [['channel_id'], 'string', 'max' => 10],
            [['down_url'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'app_id' => 'App ID',
            'app_name' => 'App Name',
            'channel_id' => 'Channel ID',
            'status' => 'Status',
            'down_url' => 'Down Url',
            'account_time' => 'Account Time',
            'create_time' => 'Create Time',
        ];
    }


    public function addInfo($data,$file_url)
    {
      $data['AccountChecking']['app_id'] = $data['appId'];
      $data['AccountChecking']['app_name'] = '';
      $data['AccountChecking']['channel_id'] = $data['payCheckDetailList'][0]['payChannel'];
      $data['AccountChecking']['status'] = '1';
      $data['AccountChecking']['down_url'] = $file_url;
      $data['AccountChecking']['account_time'] = date("Y-m-d H:i:s",$data['checkBeginTime']);
      $data['AccountChecking']['create_time'] = date("Y-m-d H:i:s");

      if ($this->load($data) and $this->validate()){
          if ($this->save(0)){
              return true;
          }
      }
      return false;


    }
}
